package study.thread.basic;

/**
 * 
 * @author Aric
 * 通过实现Runnable接口，实现多线程
 *
 */
public class MyRun implements Runnable {
	private int counter = 1;
	private int number;
	
	//构造器
	public MyRun(int num) {
		number = num;
		System.out.println("创建线程 ==> "+number);
	}
	
	//线程的主体run方法
	public void run() {
		
		while (true) {
			++counter;
			if (counter > 6) {
				System.out.println("counter = "+counter+" > 6 退出while循环，线程"+this.number+"执行run方法结束");
				return;
			}
			System.out.println("线程"+this.number+"的计数器 ==> "+counter);
		}
	}
	
	public static void main(String[] args) {
		for (int i = 0; i < 6; i++) {
			
			Runnable r = new MyRun(i+1);
			new Thread(r).start();
		}
	}

}
